﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

using SharedGenomics.Domain;
using SharedGenomics.Workbench.Core;
using SharedGenomics.Core;
using SharedGenomics.Annotations;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class AnnotationResultsView : View, IAnnotationResultsView
    {
        public AnnotationResultsView()
        {
            InitializeComponent();
        }

        private void lvwAnnotationSessions_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SelectedSessionIdChanged.Raise(this);
        }

        private void cmdRefreshList_Click(object sender, EventArgs e)
        {
            this.RefreshSessionsClicked.Raise(this);
        }

        public void NavigateTo(Uri uri)
        {
            uri.ThrowIfNull("uri");
            this.webBrowser1.Navigate(uri);
        }

        public IEnumerable<AnnotationSessionWithDescriptionInfo> AvailableSessions
        {
            set
            {
                this.lvwAnnotationSessions.Items.Clear();
                var sessionListViewItems = (value ?? Enumerable.Empty<AnnotationSessionWithDescriptionInfo>())
                    .Select(session => new ListViewItem(session.Description) { Tag = session.Id })
                    .ToArray();

                this.lvwAnnotationSessions.Items.AddRange(sessionListViewItems);
            }
        }

        public Guid? SelectedSessionId
        {
            get
            {
                return this.lvwAnnotationSessions.SelectedItems.Count > 0
                    ? (Guid?)this.lvwAnnotationSessions.SelectedItems[0].Tag
                    : (Guid?)null;
            }
        }

        public bool IsImportanceAllChecked
        {
            get { return this.rdoImportanceAll.Checked; }
        }

        public bool IsImportanceHighlightChecked
        {
            get { return this.rdoImportanceHighlight.Checked; }
        }

        public bool IsImportanceImportantChecked
        {
            get { return this.rdoImportanceImportant.Checked; }
        }

        private void ImportanceRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.ImportanceCheckedChanged.Raise(this);
        }

        public event EventHandler RefreshSessionsClicked;
        public event EventHandler ImportanceCheckedChanged;
        public event EventHandler SelectedSessionIdChanged;
    }
}
